package com.ruipengkj.component.tabbedPane;
 
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Rectangle;

import javax.swing.JTabbedPane;
import javax.swing.plaf.basic.BasicTabbedPaneUI;

public class PerTabbedPaneUI extends BasicTabbedPaneUI {

	private JTabbedPane tab = null;
    private int firstTabIndent = 5;
    private int topLinkY = 0;//上面线条的y轴

    public PerTabbedPaneUI(JTabbedPane tab) {
        this.tab = tab;
    }
    
    public PerTabbedPaneUI(JTabbedPane tab, int y) {
        this.tab = tab;
        topLinkY = y;
    }
    
    public void setTopLinkY(int y) {
    	topLinkY = y;
    }
    //控制tab的x轴
	@Override
	protected int getTabLabelShiftX(int tabPlacement, int tabIndex,
			boolean isSelected) {
		return 0;
	}
	//控制tab的y轴
	@Override
	protected int getTabLabelShiftY(int tabPlacement, int tabIndex,
			boolean isSelected) {
		return 0;
	}

	@Override
    protected Rectangle getTabBounds(int tabIndex, Rectangle dest) {
        Rectangle bounds = super.getTabBounds(tabIndex, dest);
        bounds.x += firstTabIndent;
        return bounds;
    }

    @Override
    protected void paintTabBorder(Graphics g, int tabPlacement,
            int tabIndex, int x, int y, int w, int h,
            boolean isSelected) {
    }

    @Override
    protected void paintTabBackground(Graphics g, int tabPlacement,
            int tabIndex, int x, int y, int w, int h,
            boolean isSelected) {
        //paint nothing
    }

    @Override
    protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics) {
        int width = super.calculateTabWidth(tabPlacement, tabIndex, metrics);
        //use this to remove the tab between tabs.
        return width - 5;
    }

    @Override
    protected Insets getContentBorderInsets(int tabPlacement) {
		return new Insets(1, 1,1,1);
	}
    
    protected  void paintContentBorder(Graphics g, int tabPlacement, int selectedIndex) {
    	if (topLinkY != 0) {
	    	g.setColor(new Color(225, 148, 15));
	    	g.drawLine(0, topLinkY, tab.getWidth()-1, topLinkY);
    	}
    }
    
    protected  void paintContentBorderBottomEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h){
    	
    } 
                
    protected  void paintContentBorderLeftEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h) {
    	
    }
                
    protected  void paintContentBorderRightEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h) {
    	
    }
                
    protected  void paintContentBorderTopEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h) {
    	
    }
    
    protected  void paintFocusIndicator(Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect, boolean isSelected)  {
    	
    }

}
